Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rmaiya_solution-Parser1 #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rajashreemaiya
Copy link

@sjreich
Copy link
Contributor

sjreich commented Jan 12, 2016

Assuming this actually passes (I''m too lazy to clone it and everything), 👍 . Two things to clean it up:

  1. calling #split on the string before checking it against the regex will drastically uncomplicate the regex you need.
  2. using the regexp method === instead of String#match is a bit better, because the former returns a boolean directly, whereas the latter returns the index of the match, which gets cast into a boolean.

@rajashreemaiya
Copy link
Author

👍 Noted!

@@ -1,3 +1,4 @@
def word_in_string?(word, string)
# implement with your code here
string = string.gsub(/_|-/," ")
/^(.*(\b#{word}\b).*)$/.match("#{string}")? :yes : :no

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a little curious to try to match on the entire string. You could get away with a way more simple regex, especially since you're sanitizing the input string on line 2. Check out Rubular and you might be surprised how small you can make that matcher.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants